package cn.com.dhcc.app.pub.core.job.monitor;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.base.IocBean;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.consts.AppConst;
import cn.com.dhcc.turbo.entity.registry.NodeInfo;
import cn.com.dhcc.turbo.service.monitor.gather.CmDataRealtimeGatherService;
import cn.com.dhcc.turbo.service.registry.AdapterInfoService;
import cn.com.dhcc.turbo.service.registry.BaseInfoService;

/**
 * 常规数据指标采集定时器
 */
public class CmDataRealtimeGatherCronJob extends StatefulMethodInvokingJob {
	@SuppressWarnings("deprecation")
	Logger logger = Log.getExistLogger(LOGTYPE.MONITOR);

	@Override
	public void executeInternal(JobExecutionContext context)throws JobExecutionException {
		logger.info("["+AppConst.installIp+"]"+"定时任务CmDataRealtimeGatherCronJob开始执行....");
		BaseInfoService baseInfoService=(BaseInfoService) CM.getBeanByName(IocBean.BASE_INFO_SERVICEIMPL_BEAN);
		NodeInfo localNode;
		try {
			localNode = baseInfoService.getCurrentNodeInfo();
			if (localNode==null) {
				return;
			}
		} catch (ServiceException e) {
			logger.error("获取本节点信息失败:"+e);
		}
		logger.info("cm data gathering...");
		AdapterInfoService adapterInfoService = CM.getBean(AdapterInfoService.class);
		if(!adapterInfoService.isLocalAdapterCreate()){
			return;
		}
		CmDataRealtimeGatherService cmDataGatherService = CM.getBean(CmDataRealtimeGatherService.class);
		cmDataGatherService.cmStructuredRecvFailNumForAdapter();
		cmDataGatherService.cmStructuredRecvSuccessNumForAdapter();
		cmDataGatherService.cmStructuredRecvSuccessRateForAdapter();
		
		cmDataGatherService.cmStructuredSendFailNumForAdapter();
		cmDataGatherService.cmStructuredSendSendingNumForAdapter();
		cmDataGatherService.cmStructuredSendSuccessNumForAdapter();
		cmDataGatherService.cmStructuredSendWaitNumForAdapter();
		cmDataGatherService.cmStructuredSendSuccessRateForAdapter();
		cmDataGatherService.autoGatherNodeAndDomainOntimeValue();
		logger.info("["+AppConst.installIp+"]"+"定时任务CmDataRealtimeGatherCronJob执行结束....");
	}

}
